## Predict excess returns with yields and trend proxies
## Table 2: predictive regressions with pi-star, r-star, i-star
library(xtable) # xtable()
library(VAR.etp) # for bootstrap
source("R/data_fns.R")
setwd("/Users/rcerkc01/Desktop/BauerRudebusch/115622-V1")
## Predict excess returns with yields and trend proxies
## Table 2: predictive regressions with pi-star, r-star, i-star
library(xtable) # xtable()
library(VAR.etp) # for bootstrap
source("R/data_fns.R")
source("R/util_fns.R")
source("R/bootstrap_fns.R")
bootstrap_flag <- TRUE
M <- 5000
data <- loadData()
data$istar <- data$pistar.ptr + data$rstar.realtime
yield.cols <- attr(data, "yield.cols")
mats <- as.numeric(substr(yield.cols, 2, 5))
Y <- data.matrix(data[,yield.cols])
rstar.nms <- c("rstar.filt", "rstar.realtime", "rr.ewma")
rstar.desc <- c("filtered", "real-time", "mov.~avg.")
row.nms <- c("PC1", "", "PC2", "", "PC3", "",
"$\\pi_t^\\ast$", "", "",
"$r_t^\\ast$", "", "",
"$i_t^\\ast$", "", "",
"$R^2$",
"Memo: $r^\\ast$")
## annual returns
h <- 4
vcovfn <- function(mod) sandwich::NeweyWest(mod, lag=6, prewhite=FALSE)
## quarterly returns
## h <- 1
## vcovfn <- function(mod) sandwich::vcovHC(mod, type="HC0")
xrn <- excess_returns(Y, mats, h)
data$xr <- rowMeans(xrn)
subsample = FALSE
## create PCs
PCs <- makePCs(Y)
data[paste0("PC", 1:3)] <- PCs
W <- attr(PCs, "W")
## scaled PCs (can't use in bootstrap where orthonormal vector are needed)
sc <- c(sum(W[,1]), W[nrow(W),2]-W[1,2], W[nrow(W),3]-2*W[mats==2,3]+W[1,3])
data[paste0("PC", 1:3, "sc")] <- PCs %*% diag(1/sc)
## for bootstrap
attr(data, 'W') <- W
attr(data, 'mats') <- mats
attr(data, 'yield.cols') <- yield.cols
fmla.0 <- xr ~ PC1 + PC2 + PC3
rstar.nms
i = 5
fmla <- formula(paste0("xr ~ PC1sc + PC2sc + PC3sc + pistar.ptr + ", rstar.nms[i-2]))
fmla
bootstrap_flag
fmla.a <- formula(paste0("xr ~ PC1 + PC2 + PC3 + pistar.ptr + ", rstar.nms[i-2]))
fmla.a
dgp <- getBootDGP(c("PC1", "PC2", "PC3"), c("pistar.ptr", rstar.nms[i-2]), data[ind,], BC=TRUE)
if (subsample) {
cat("Post-1985 subsample:\n")
ind <- data$yyyymm >= 198501
} else {
cat("Full sample:\n")
ind <- 1:nrow(data)
}
dgp <- getBootDGP(c("PC1", "PC2", "PC3"), c("pistar.ptr", rstar.nms[i-2]), data[ind,], BC=TRUE)
rval <- bootstrapTest(fmla.0, fmla.a, data[ind,], dgp, h, M, vcovfn)
